package com.atguigu.controller;

import com.atguigu.mapper.SysMenuMapper;
import com.atguigu.model.system.SysMenu;
import com.atguigu.model.system.SysRole;
import com.atguigu.result.Result;
import com.atguigu.service.SysMenuService;
import com.atguigu.vo.system.AssginMenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysMenu")
@Api(tags="菜单管理")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @ApiOperation("获取菜单")
    @GetMapping("findNodes")
    public Result findNodes(){
        List<SysMenu> sysMenus=sysMenuService.findNodes();
        return Result.ok(sysMenus);
    }
    @ApiOperation("新增菜单")
    @PostMapping("save")
    public Result save(@RequestBody SysMenu sysMenu){
        sysMenuService.save(sysMenu);
        return Result.ok();
    }
    @ApiOperation("修改菜单")
    @PutMapping("update")
    public Result update(@RequestBody SysMenu sysMenu){
        sysMenuService.updateById(sysMenu);
        return Result.ok();
    }
    @ApiOperation("根据id删除菜单")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id){
        sysMenuService.deleteById(id);
        return Result.ok();
    }
    @ApiOperation("修改菜单状态")
    @PutMapping("/switchStatus/{id}/{status}")
    public Result switchStatus(@PathVariable Integer id,@PathVariable Integer status){
        sysMenuService.switchStatus(id,status);
        return Result.ok();
    }
    @ApiOperation("根据角色id获取菜单")
    @GetMapping("/toAssign/{roleId}")
    public Result toAssign(@PathVariable Long roleId){
       List<SysMenu> sysMenuList= sysMenuService.toAssign(roleId);
       return Result.ok(sysMenuList);
    }
    @ApiOperation(value = "根据角色分配权限")
    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssginMenuVo assginMenuVo){
        sysMenuService.doAssign(assginMenuVo);
        return Result.ok();
    }
}
